'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:UserdataCtrl
 * @description
 * # UserdataCtrl
 * Controller of the webApp
 */

angular.module('webApp')
  .controller('userData', function ($scope,$rootScope,promiseUserData,popBox,cookie) {
  $scope.$on('$stateChangeSuccess',function(){
    //判断是否登录
    if(cookie.getCookie('access_token')){
      promiseUserData.getUserData().then(function(data){
        if(data.avatar_url == "/uploads/images/avatar/default.png"){
          $scope.userHead = 'images/userOriginHead.png' + '?' + Math.random();
        }
        else{
          $scope.userHead = data.avatar_url + '?' + Math.random();
        }
        //用户标签
        $scope.userTags = [
          {
            name: '邮箱',
            userData: data.email
          },
          {
            name: '姓名',
            userData: data.name
          },
          {
            name: '性别',
            userData: data.gender
          },
          {
            name: '职位',
            userData: data.company
          }
        ];
      })
    }
  });
});
